package features.advance.leetcode.tree.model;

import features.advance.leetcode.util.TreeUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class TreeNode<E> {
    public E val;
    public int index;
    public TreeNode<E> left;
    public TreeNode<E> right;

    public TreeNode(){

    }
    public TreeNode(E x) {
        val = x;
    }
    public TreeNode(E x, int index){
        val = x;
        this.index = index;
    }
    public TreeNode(E val, TreeNode<E> left, TreeNode<E> right){
        this.val = val;
        this.left = left;
        this.right = right;
    }


    public TreeNode<E> search(TreeNode<E> root,E e){

        if(root!=null){
            if(root.val == e){
                return root;
            }
            TreeNode<E> left = search(root.left, e);
            if(left!=null){
                return left;
            }
            TreeNode<E> right = search(root.right, e);
            if(right!=null){
                return right;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        TreeNode<Integer> root = TreeUtil.stringToTreeNode("[6,3,8,1,5,7,9,0,2]");
        TreeUtil.post_order(root);
        TreeUtil.pre_order(root);
        TreeUtil.middle_order(root);
    }
}
